<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Examples extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		
		$this->load->database();
		$this->load->helper('url');
		
		$this->load->library('grocery_CRUD');	
	}
	
	function _example_output($output = null)
	{
		$this->load->view('example.php',$output);	
	}
	
	function offices()
	{
		$output = $this->grocery_crud->render();

		$this->_example_output($output);
	}
	
	function index()
	{
		$this->_example_output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array()));
	}	



//-------------------------------------------------



	function product()
	{
		try{
			$crud = new grocery_CRUD();


			$crud->set_table('sanpham');
			$crud->set_subject('sanpham');
			$crud->set_field_upload('img','assets/uploads/images'); //tao file upload
			 $crud->set_relation('cate_id','category','name');  //khoa ngoai
             $crud->required_fields('masp');  //truong bat buoc nhap
			
			$output = $crud->render();
			
			$this->_example_output($output);
			
		}catch(Exception $e){
			show_error($e->getMessage().' --- '.$e->getTraceAsString());
		}
	}
	
	function category()
    	{
    		try{
    			$crud = new grocery_CRUD();


    			$crud->set_table('category');
    			$crud->set_subject('category');
                 $crud->required_fields('name');  //truong bat buoc nhap


    			$output = $crud->render();

    			$this->_example_output($output);

    		}catch(Exception $e){
    			show_error($e->getMessage().' --- '.$e->getTraceAsString());
    		}
    	}
}